package com.awesome.spring.nacos.config;

/**
 * @program: awesome-spring
 * @description: 日志
 * @author: Alex Wu
 * @createDate: 2025-02-06 14:56
 **/
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class NacosLogger implements CommandLineRunner {

    private final Environment environment;

    public NacosLogger(Environment environment) {
        this.environment = environment;
    }

    @Value("${config:未加载}")
    private String configValue;

    @Override
    public void run(String... args) {
        System.out.println("====================================");
        System.out.println("✅ Nacos 配置已加载:");
        System.out.println("✅ Data ID: " + environment.getProperty("spring.application.name") + ".yml");
        System.out.println("✅ Nacos Server: " + environment.getProperty("spring.cloud.nacos.config.server-addr"));
        System.out.println("✅ 配置项【config】: " + environment.getProperty("config", "未找到"));
        System.out.println("✅ 激活的环境: " + Arrays.toString(environment.getActiveProfiles()));
        System.out.println("====================================");
    }
}
